class Music(val title: String, val artist: String, val duration: Int) {  
  override def toString: String = s"Title: $title, Artist: $artist, Duration: $duration seconds"  
}  
  
class MusicPlayer {  
  private var musicList: List[Music] = List.empty  
  private var currentMusic: Option[Music] = None  
  private var playMode: String = "normal" // normal, shuffle, loop, etc.  
  
  // 添加音乐到播放列表  
  def addMusic(music: Music): Unit = {  
    musicList = music :: musicList  
  }  
  
  // 从播放列表中删除音乐  
  def removeMusic(music: Music): Unit = {  
    musicList = musicList.filterNot(_ == music)  
    if (currentMusic.contains(music)) {  
      currentMusic = None  
    }  
  }  
  
  // 播放音乐，支持多种播放模式  
  def playMusic(): Unit = {  
    currentMusic match {  
      case Some(music) =>  
        println(s"Playing: $music")  
        // 这里可以添加播放音乐的逻辑，比如调用某个API播放音乐  
      case None =>  
        playMode match {  
          case "normal" =>  
            if (musicList.nonEmpty) {  
              currentMusic = Some(musicList.head)  
              playMusic()  
            } else {  
              println("No music to play.")  
            }  
          case "shuffle" =>  
            val shuffledList = scala.util.Random.shuffle(musicList)  
            if (shuffledList.nonEmpty) {  
              currentMusic = Some(shuffledList.head)  
              playMusic()  
            } else {  
              println("No music to play.")  
            }  
          case "loop" =>  
            if (musicList.nonEmpty) {  
              currentMusic = Some(musicList.head)  
              playMusic() // 在循环模式下，这里应该实现一个循环逻辑  
            } else {  
              println("No music to play.")  
            }  
          case _ =>  
            println(s"Unsupported play mode: $playMode")  
        }  
    }  
  }  
  
  // 设置播放模式  
  def setPlayMode(mode: String): Unit = {  
    playMode = mode  
  }  
  
  // 获取当前播放的音乐  
  def getCurrentMusic: Option[Music] = currentMusic  
  
  // 获取播放列表  
  def getMusicList: List[Music] = musicList  
}  
  
// 使用示例  
object MusicPlayerDemo {  
  def main(args: Array[String]): Unit = {  
    val player = new MusicPlayer()  
  
    // 添加音乐到播放列表  
    player.addMusic(new Music("Song 1", "Artist 1", 240))  
    player.addMusic(new Music("Song 2", "Artist 2", 180))  
    player.addMusic(new Music("Song 3", "Artist 3", 300))  
  
    // 打印播放列表  
    println("Music List:")  
    player.getMusicList.foreach(println)  
  
    // 播放音乐  
    player.playMusic()  
  
    // 切换到随机播放模式  
    player.setPlayMode("shuffle")  
    player.playMusic()  
  
    // 从播放列表中删除一首歌  
    player.removeMusic(new Music("Song 2", "Artist 2", 180))  
    println("Music List after removing a song:")  
    player.getMusicList.foreach(println)  
  
    // 再次播放音乐  
    player.playMusic()  
  }  
}
